@extends('layouts.admin')

@section('title', '|博客')

@section('content')

        <h3>博客列表</h3>
        <table class="table table-condensed table-striped table-bordered table-responsive" data-page-length="200" data-paging="false" id="article-list-table">
            <thead>
            <tr>
                <th>#</th>
                <th>标题</th>
                <th>封面</th>
                <th>SEO关键字</th>
                <th>SEO描述</th>
                <th>来源</th>

                <th>创建时间</th>
                <th>修改时间</th>
                <th>操作</th>
            </tr>
            </thead>

            <tbody>
            @foreach($articles as $article)
                <tr>
                    <td>{{$article->id}}</td>
                    <td>
                        <a href="{{route('article.show',$article)}}" class="text-info" target="_blank">{{$article->title}}</a><br>
                    </td>
                    <td><a href='{{$article->coverage_url}}' target='_blank'>{{$article->coverage_url}}</a></td>
                    <td>{{$article->keyword}}</td>
                    <td>{{$article->description}}</td>
                    <td><a href="{{$article->url_provider}}" target="_blank">{{$article->url_provider}} </a></td>
                    <td>{{$article->created_at->diffForHumans()}}</td>
                    <td>{{$article->updated_at->diffForHumans()}}</td>
                    <td>
                        <a class="btn btn-xs btn-warning " href={{route('article.edit',$article)}} role="button"> 编辑</a>
                        <button class="btn btn-xs {{$article->is_show ? 'btn-success' : 'btn-danger'}}" id="{{$article->id}}" onClick="publishTrigger({{$article->id}})">{{$article->is_show ? '隐藏' : '发表'}} </button>
                        <a href="http://www.cnfluffy.com/article/{{$article->id}}" class=" btn btn-xs btn-primary" target="_blank">小站</a>

                    </td>
                </tr>
            @endforeach
            </tbody>
        </table>



        <h4 class="text-center center-block text-danger" style="height:40px">
            {!! $articles->links() !!}
        </h4>

        {{--<div class="center-block">--}}
            {{--{!! $articles->render() !!}--}}

        {{--</div>--}}

@endsection

@section('scripts')
    <script>
        function publishTrigger(articleId) {
            $.post("/article/publishTriggerAction",
                    {articleId:articleId, '_token': '{{csrf_token()}}',
                    },
                    function(data,status){
                        if(status == 'success') {
                            if(data.code == 1) {
                                alert(data.message+'成功');
                                $('#'+articleId).text(data.message);
                            } else {
                                alert(data.message);
                            }
                        }

                    });
        };

        $(function () {
            $('#article-list-table').DataTable(
                {
                    "order": [[0, "desc"]],

                }
            );
        })
    </script>
@endsection
